package com.zzptc.ly.a12_1;

import android.graphics.Color;
import android.os.Bundle;

import androidx.fragment.app.Fragment;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.github.mikephil.charting.charts.BarChart;
import com.github.mikephil.charting.components.XAxis;
import com.github.mikephil.charting.data.BarData;
import com.github.mikephil.charting.data.BarDataSet;
import com.github.mikephil.charting.data.BarEntry;

import java.util.ArrayList;
import java.util.List;


public class SecondFragment extends Fragment {

    public SecondFragment() {
        // Required empty public constructor
    }
    // TODO: Rename and change types and number of parameters
    public static SecondFragment newInstance(String param1, String param2) {
        SecondFragment fragment = new SecondFragment();
        Bundle args = new Bundle();
        return fragment;
    }
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_second, container, false);
        BarChart barChart = view.findViewById(R.id.barcChart);
        List<BarEntry> data=new ArrayList<>();
        data.add(new BarEntry(1,10));
        data.add(new BarEntry(2,9));
        data.add(new BarEntry(3,8));
        data.add(new BarEntry(4,7));
        data.add(new BarEntry(5,6));
        BarDataSet dataSet = new BarDataSet(data, "");
        dataSet.setColor(Color.RED);
        List<BarEntry> mData=new ArrayList<>();
        mData.add(new BarEntry(10,1));
        mData.add(new BarEntry(5,3));
        mData.add(new BarEntry(7,5));
        mData.add(new BarEntry(8,4));
        mData.add(new BarEntry(3,3));
        BarDataSet mDataSet = new BarDataSet(mData, "");
        mDataSet.setColor(Color.BLUE);
   //将上两个BarDataSet对象放入BarData中
        BarData barData = new BarData(dataSet);
        barData.addDataSet(mDataSet);
        barChart.setData(barData);
        //布局中的控件与数据关联
        barChart.getXAxis().setPosition(XAxis.XAxisPosition.BOTTOM);
        barChart.getAxisRight().setEnabled(false);
        barChart.getDescription().setEnabled(false);
        barData.groupBars(1,0.6f,0);
      //  barData.setBarWidth(0.2f);
        barChart.getXAxis().setAxisMaximum(12);
        barChart.getXAxis().setAxisMinimum(1);
        barChart.getXAxis().setLabelCount(5,false);
        barChart.getXAxis().setCenterAxisLabels(true);

        return view;
    }
}
